﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace ProjetS5
{
    public class InterfaceBar
    {
        private void addKeys()
        {
            shortcuts.Add(Keys.D1, '&');
            shortcuts.Add(Keys.D2, 'é');
            shortcuts.Add(Keys.D3, '"');
            shortcuts.Add(Keys.D4, '\'');
            shortcuts.Add(Keys.D5, '(');
            shortcuts.Add(Keys.D6, '-');
            shortcuts.Add(Keys.D7, 'è');
            shortcuts.Add(Keys.D8, '_');
            shortcuts.Add(Keys.D9, 'ç');
            shortcuts.Add(Keys.D0, 'à');
            shortcuts.Add(Keys.OemOpenBrackets, ')');
            shortcuts.Add(Keys.OemPlus, '=');
        }

        public InterfaceBar()
        {
            onScreenPosition = new Vector2(10, 570);
            nbButtons = 12;
            abilityBoxes = new List<Box>();
            abilities = new List<Ability>();
            shortcuts = new Dictionary<Keys, char>();
            addKeys();

            for (int i = 0 ; i < nbButtons ; i++)
            {
                abilityBoxes.Add(new Box(new Vector2(10 + buttonSize.X * i, onScreenPosition.Y), buttonSize, Color.Transparent, new Color(150, 150, 150, 10)));
                abilities.Add(null);
            }
            
            box = new Box(onScreenPosition, new Vector2(buttonSize.X * nbButtons, buttonSize.Y), Color.LightSlateGray, Color.LightSlateGray);
        }

        public Dictionary<Keys, char> shortcuts;
        public Box box;
        public static Vector2 buttonSize = new Vector2(40);
        public static SpriteFont font;
        public Vector2 onScreenPosition;
        public byte nbButtons;
        public List<Box> abilityBoxes;
        public List<Ability> abilities;
        public void AddAbility(byte index, Ability toAdd)
        {
            abilities[index] = toAdd;
        }
        public void RemoveAbility(byte index)
        {
            abilities[index] = null;
        }
        public void SwapAbilities(byte indexN1, byte indexN2)
        {
            Ability tmp = abilities[indexN2];
            abilities[indexN2] = abilities[indexN1];
            abilities[indexN1] = tmp;
        }

        public void Draw(Game game, SpriteBatch spriteBatch, float targetDistance)
        {
            box.Draw(spriteBatch);
            for (int i = 0 ; i < abilities.Count ; i++)
            {
                if (abilities[i] != null)
                {
                    spriteBatch.Draw(abilities[i].ability.Icon, new Vector2(onScreenPosition.X + buttonSize.X * i, onScreenPosition.Y), (targetDistance > abilities[i].ability.Range) ? new Color(255, 100, 100) : Color.White);
                    abilityBoxes[i].Draw(spriteBatch);
                    spriteBatch.DrawString(font, shortcuts.ElementAt(i).Value.ToString(), new Vector2(onScreenPosition.X + buttonSize.X * i + 27, onScreenPosition.Y - 2), Color.White, 0, Vector2.Zero, 0.8f, SpriteEffects.None, 0);
                }
            }
        }
    }
}
